feat: configurable editor experience for harpoon -e - #8
Open
pilot322 wants to merge 1 commit into
Open
Conversation
Adds two tmux options that customise how the edit popup behaves when `$EDITOR` is vim or nvim: - `@tmux-harpoon-faithful-vim-controls` (bool, default `true`): remap `q` -> `:q!`, `:w` -> `:wq`, and `<CR>` -> jump to the session on the current line, so the edit popup navigates and exits like the rest of the harpoon UI. Set to `false` to keep stock vim behaviour. - `@tmux-harpoon-editor-args` (string, default empty): extra args appended to the editor invocation (e.g. `--clean`, `-u NONE`) for users who want a lighter editor instance for this popup. Also fixes a quoting bug in `_getFZFCmd`: the `fzf-tmux -p '50%,50%'` form passed literal single quotes around the size argument because the caller word-splits the unquoted command. fzf-tmux exits with status 2 and the popup never spawns, breaking `harpoon -l` on systems that fall back to fzf-tmux (fzf < 0.53).
There was a problem hiding this comment.
Pull request overview
This PR enhances the harpoon -e edit popup when $EDITOR is vim/nvim by making the popup behavior configurable via tmux options, and fixes an fzf-tmux invocation quoting issue that could prevent the list popup from opening on older fzf versions.
Changes:
- Fix
_getFZFCmdto return a usablefzf-tmux -p 50%,50%command string (without literal single quotes being passed through). - Add vim/nvim-specific edit-popup behavior controlled by
@tmux-harpoon-faithful-vim-controlsand@tmux-harpoon-editor-args.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+141
to
+146
| # Tmux options (vim/nvim only): | ||
| # @tmux-harpoon-faithful-vim-controls bool, default true | ||
| # Remap `q` -> :q!, `:w` -> :wq, and <CR> -> jump to session on the | ||
| # current line, mirroring how harpoon's UI navigates. | ||
| # @tmux-harpoon-editor-args string, default empty | ||
| # Extra args appended to the editor command (e.g. `--clean`, `-u NONE`). |
Comment on lines
+147
to
+148
| edit_file() { | ||
| cmd="$EDITOR $cachefile" |
Comment on lines
+153
to
+156
| faithful=$(tmux show-option -gqv "@tmux-harpoon-faithful-vim-controls" 2>/dev/null) | ||
| [ -z "$faithful" ] && faithful="true" | ||
| if [ "$faithful" = "true" ]; then | ||
| cmd="$cmd -c \"nnoremap q :q!<CR>\" -c \"cnoreabbrev w wq\" -c \"nnoremap <silent> <CR> :execute '!$0 -s ' . line('.') <bar> q!<CR>\"" |
| faithful=$(tmux show-option -gqv "@tmux-harpoon-faithful-vim-controls" 2>/dev/null) | ||
| [ -z "$faithful" ] && faithful="true" | ||
| if [ "$faithful" = "true" ]; then | ||
| cmd="$cmd -c \"nnoremap q :q!<CR>\" -c \"cnoreabbrev w wq\" -c \"nnoremap <silent> <CR> :execute '!$0 -s ' . line('.') <bar> q!<CR>\"" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two tmux options that customize how the edit popup behaves when
$EDITORis vim or nvim, in order to provide a more similar experience to harpoon:@tmux-harpoon-faithful-vim-controls(bool, defaulttrue): remapq->:q!,:w->:wq, and<CR>-> jump to the session on the current line, so the edit popup navigates and exits like the rest of the harpoon UI. Set tofalseto keep stock vim behaviour.@tmux-harpoon-editor-args(string, default empty): extra args appended to the editor invocation (e.g.--clean,-u NONE) for users who want a lighter editor instance for this popup.Also fixes a quoting bug in
_getFZFCmd: thefzf-tmux -p '50%,50%'form passed literal single quotes around the size argument because the caller word-splits the unquoted command. fzf-tmux exits with status 2 and the popup never spawns, breakingharpoon -lon systems that fall back to fzf-tmux (fzf < 0.53).I made the faithful vim controls the default behavior as it's closest to what the edit popup in harpoon comes with, so users don't have to relearn the window's behavior. I use this window a lot both in vim and in the plugin and it felt a bit awkward.